<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 李邦琦 <1536549251@qq.com>
// +----------------------------------------------------------------------

namespace app\crm\controller;
use think\Loader;
use think\Cache;

class Taskcount extends CrmController
{
    /**
     * taskCount
     */
    public function taskCount()
    {
        $menuname = "Task Count";
        $p_menuname = $_SESSION['menu'][$menuname]; //父菜单
        $priv = $_SESSION["user_priv"][$p_menuname][$menuname];
        $this->assign("priv",$priv);

        $arrUsers = Loader::model('Users')->getUsersList();
        $this->assign("arrUsers",$arrUsers);
        // 模板输出
        return $this->fetch('taskCount');
    }


    public function taskCountData () 
    {
        $where = "(1 ";
        $where .= empty($_REQUEST["username"])?"":" AND username = '".$_REQUEST["username"]."'";
        $where .= empty($_REQUEST["createuser"])?"":" AND createuser = '".$_REQUEST["createuser"]."'";
        $where .= empty($_REQUEST["id"])?"":" AND id = '".$_REQUEST["id"]."'";
        $where .= empty($_REQUEST["start_createtime"])?"":" AND createtime > '".$_REQUEST["start_createtime"]."'";
        $where .= empty($_REQUEST["end_createtime"])?"":" AND createtime < '".$_REQUEST["end_createtime"]."'";
        $where .= " )";

        $arrData = Loader::model('Taskcount')->taskCountData($where);
        echo json_encode($arrData);
    }


    /**
     * taskDetail
     */
    public function taskDetail()
    {
        $menuname = "Task Count";
        $p_menuname = $_SESSION['menu'][$menuname]; //父菜单
        $priv = $_SESSION["user_priv"][$p_menuname][$menuname];
        $this->assign("priv",$priv);
        
        $this->assign("task_id",$_REQUEST['id']);
        /*$arrUsers = Loader::model('Users')->getUsersList();
        $this->assign("arrUsers",$arrUsers);*/
        // 模板输出
        return $this->fetch('taskDetail');
    }


    public function taskDetailData ()
    {
        $arrData = Loader::model('Taskcount')->taskDetailData($_REQUEST['task_id']);
        echo $arrData['task_result'];exit;
    }


    /**
     * 删除
     */
    public function delIllness ()
    {
        $id = $_REQUEST['ids'];
        // $id = '1|';
        $ids = explode('|', $id);
        $id_str = "(";
        foreach ($ids as $v) {
            $id_str .= $v.',';
        }
        $id_str = rtrim($id_str, ',');
        $id_str .= ")";
        $where = "id IN $id_str";
        Loader::model('Customer')->delIllness($where);
    }




}